package com.emperorque.mathpractice.controller;

import com.emperorque.mathpractice.model.Expression;
import com.emperorque.mathpractice.model.ExpressionType;
import com.emperorque.mathpractice.service.ExpressionGenerator;
import com.emperorque.mathpractice.view.ExpressionPrinter;

import java.util.List;

/**
 * 数学练习控制器
 * 协调服务层和视图层的交互
 */
public class MathPracticeController {
    
    private final ExpressionGenerator generator;
    private final ExpressionPrinter printer;
    
    /**
     * 构造函数
     * @param generator 算式生成器
     * @param printer 算式打印器
     */
    public MathPracticeController(ExpressionGenerator generator, ExpressionPrinter printer) {
        if (generator == null) {
            throw new IllegalArgumentException("算式生成器不能为空");
        }
        if (printer == null) {
            throw new IllegalArgumentException("算式打印器不能为空");
        }
        this.generator = generator;
        this.printer = printer;
    }
    
    /**
     * 生成并打印简单算式（纯加减法）
     * @param count 生成数量
     */
    public void generateSimpleExpressions(int count) {
        List<Expression> expressions = generator.generate(count, ExpressionType.SIMPLE);
        printer.print(expressions, "【纯加减法算式练习题】");
    }
    
    /**
     * 生成并打印混合算式（加减混合）
     * @param count 生成数量
     */
    public void generateMixedExpressions(int count) {
        List<Expression> expressions = generator.generate(count, ExpressionType.MIXED);
        printer.print(expressions, "【加减混合算式练习题】");
    }
    
    /**
     * 生成两套独立的习题集
     * @param count 每套题目数量
     */
    public void generateBothSets(int count) {
        generateSimpleExpressions(count);
        generateMixedExpressions(count);
    }
}
